//
// Created by Win10 on 2022/10/30.
//

#include<iostream>
#include "c_queue.h"

using namespace std;

void InitQueue(CQueue &Q) {
    Q.front = Q.rear = Q.size = 0;
}

bool QueueEmpty(CQueue Q) {
    if (Q.size == 0) return true;
    return false;
}

bool QueueFull(CQueue Q) {
    if (Q.size == MaxSize) return true;
    return false;
}

bool EnQueue(CQueue &Q, ElemType x) {
    if (QueueFull(Q)) return false;
    Q.data[Q.rear] = x;
    Q.rear = (Q.rear + 1) % MaxSize;
    Q.size++;
    return true;
}

bool DeQueue(CQueue &Q, ElemType &x) {
    if (QueueEmpty(Q)) return false;
    x = Q.data[Q.front];
    Q.front = (Q.front + 1) % MaxSize;
    Q.size--;
    return true;
}

bool GetHead(CQueue Q, ElemType &x) {
    if (QueueEmpty(Q)) {
        return false;
    }
    x = Q.data[Q.front];
    return true;
}

int GetSize(CQueue Q) {
    return Q.size;
}

int main() {
    {
        CQueue Q;
        InitQueue(Q);

        for (int i = 1; i <= 5; i++) {
            bool f = EnQueue(Q, i);
            if (!f) cout << i << endl;
        }
        ElemType x;
        DeQueue(Q, x);
        cout << x << endl;
        DeQueue(Q, x);
        cout << x << endl;
        EnQueue(Q, 1);
        EnQueue(Q, 2);
        cout << Q.front << " " << Q.rear << endl;
        if (!EnQueue(Q, 6)) {
            cout << "队列已满" << endl;
        }
        GetHead(Q, x);
        cout << x << endl << endl;
        while (!QueueEmpty(Q)) {

            DeQueue(Q, x);
            cout << x << endl;
        }
    }
    return 0;
}